package com.ruoyi.petition.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.petition.domain.LawyerInfo;
import com.ruoyi.petition.mapper.LawyerInfoMapper;
import com.ruoyi.petition.service.ILawyerInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 律师信息Service业务层处理
 *
 * @author ZWX
 * @date 2025-07-29
 */
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class LawyerInfoServiceImpl extends ServiceImpl<LawyerInfoMapper, LawyerInfo> implements ILawyerInfoService {
    private final LawyerInfoMapper lawyerInfoMapper;

    /**
     * 查询律师信息
     *
     * @param id 律师信息主键
     * @return 律师信息
     */
    @Override
    public LawyerInfo selectLawyerInfoById(Long id) {
        LawyerInfo lawyerInfo = lawyerInfoMapper.selectLawyerInfoById(id);
        String sex = lawyerInfo.getSex();
        if (StringUtils.isNotBlank(sex)) {
            lawyerInfo.setSexName(DictUtils.getDictLabel("sys_user_sex", sex));
        }
        return lawyerInfo;
    }

    /**
     * 查询律师信息列表
     *
     * @param lawyerInfo 律师信息
     * @return 律师信息
     */
    @Override
    public List<LawyerInfo> selectLawyerInfoList(LawyerInfo lawyerInfo) {
        List<LawyerInfo> lawyerInfoList = lawyerInfoMapper.selectLawyerInfoList(lawyerInfo);
        lawyerInfoList.forEach(item -> {
            String sex = item.getSex();
            if (StringUtils.isNotBlank(sex)) {
                item.setSexName(DictUtils.getDictLabel("sys_user_sex", sex));
            }
        });
        return lawyerInfoList;
    }

    /**
     * 新增律师信息
     *
     * @param lawyerInfo 律师信息
     * @return 结果
     */
    @Override
    public int insertLawyerInfo(LawyerInfo lawyerInfo) {
        lawyerInfo.setCreateTime(DateUtils.getNowDate());
        return lawyerInfoMapper.insertLawyerInfo(lawyerInfo);
    }

    /**
     * 修改律师信息
     *
     * @param lawyerInfo 律师信息
     * @return 结果
     */
    @Override
    public int updateLawyerInfo(LawyerInfo lawyerInfo) {
        lawyerInfo.setUpdateTime(DateUtils.getNowDate());
        return lawyerInfoMapper.updateLawyerInfo(lawyerInfo);
    }

    /**
     * 批量删除律师信息
     *
     * @param ids 需要删除的律师信息主键
     * @return 结果
     */
    @Override
    public int deleteLawyerInfoByIds(Long[] ids) {
        return lawyerInfoMapper.deleteLawyerInfoByIds(ids);
    }

    /**
     * 删除律师信息信息
     *
     * @param id 律师信息主键
     * @return 结果
     */
    @Override
    public int deleteLawyerInfoById(Long id) {
        return lawyerInfoMapper.deleteLawyerInfoById(id);
    }
}
